package helperclasses;

import javax.sql.DataSource;

import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;

public class DbUtil {

	private static DbUtil instance = null;
	private MysqlDataSource ds;
	static private String userName;
	static private String password;
	static private String url;

	public static void setValues(String userName1, String password1, String url1) {
		userName = userName1;
		password = password1;
		url = url1;
	}

	/** Constructor that creates the connection with the database */
	private DbUtil() {

		ds = new MysqlDataSource();

		ds.setUrl(url);
		ds.setUser(userName);
		ds.setPassword(password);

	}

	/** Get method that also creates a new instance of DbUtil if there is no one */
	public static DbUtil getInstance() {
		if (instance == null) {
			instance = new DbUtil();
		}

		return instance;
	}

	/** Get method */
	public DataSource getDataSource() {
		return ds;
	}

}